<?php
/**
 * Created by PhpStorm.
 * User: Vito
 * Date: 2022/6/21
 * Time: 11:03
 */

namespace app\service;


use think\App;
use think\Cache;

class CaptchaCacheService extends Cache
{
    protected $key;

    public function __construct(App $app, $key = '')
    {
        parent::__construct($app);
        $this->key = $key;
    }

    public function set($key, $value, $ttl = null): bool
    {
        $key = $this->getKey($key);

        return parent::set($key, $value, $ttl); // TODO: Change the autogenerated stub
    }

    public function get($key, $default = null)
    {
        $key = $this->getKey($key);

        return parent::get($key, $default); // TODO: Change the autogenerated stub
    }

    public function has($key): bool
    {
        $key = $this->getKey($key);

        return parent::has($key); // TODO: Change the autogenerated stub
    }

    public function delete($key): bool
    {
        $key = $this->getKey($key);
        return parent::delete($key); // TODO: Change the autogenerated stub
    }

    protected function getKey($key)
    {
        return ($this->key ? $this->key . '_' : '') . $key;
    }
}